<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/24
 * Time: 10:49
 */

namespace app\api\model;


use redis\RedisPackage;
use think\Db;
use think\Model;


class ConstructionNode extends Model
{
    /*
     *
     * 施工节点
     */
    public function List($orderId, $type)
    {
        $auxiliary_delivery_node = \db('auxiliary_delivery_node')
            ->field('count(auxiliary_delivery_schedul_id) as nodeId,sum(DISTINCT if(auxiliary_delivery_node.state=1,1,0)) as nodeIds,auxiliary_delivery_schedul_id')
            ->group('auxiliary_delivery_schedul_id')
            ->buildSql();

        $auxiliary_delivery_schedule = \db('auxiliary_delivery_schedule')
            ->field('count(auxiliary_delivery_schedule.id) as scheduleId,node.nodeId,sum(nodeIds) as nodeIds,node.auxiliary_delivery_schedul_id,auxiliary_delivery_schedule.auxiliary_project_list_id')
            ->join([$auxiliary_delivery_node => 'node'], 'node.auxiliary_delivery_schedul_id=auxiliary_delivery_schedule.id', 'left')
            ->whereNull('auxiliary_delivery_schedule.delete_time')
            ->group('auxiliary_project_list_id')
            ->buildSql();


        $capital = db('auxiliary_project_list')
            ->join([$auxiliary_delivery_schedule => 'schedule'], 'auxiliary_project_list.id=schedule.auxiliary_project_list_id', 'left')
            ->join('capital', 'capital.capital_id=auxiliary_project_list.capital_id', 'left')
            ->join('order', 'order.order_id=auxiliary_project_list.order_id', 'left')
            ->field('auxiliary_project_list.capital_id,schedule.scheduleId,ifnull(schedule.nodeId,0) as nodeId,ifnull(schedule.nodeIds,0) as nodeIds,schedule.auxiliary_delivery_schedul_id,concat(capital.class_b,"(",square,"/",company,")") as class_b,capital.cooperation,auxiliary_project_list.auxiliary_id,auxiliary_project_list.id,order.state')
            ->where('auxiliary_project_list.order_id', $orderId)
            ->where('capital.types', 1)
            ->where('capital.enable', 1)
            ->whereNull('auxiliary_project_list.delete_time');
        if ($type == 1) {
            $capital->where(
                function ($quer) {
                    $quer->whereNull('nodeId')->whereOr('scheduleId !=nodeIds');;
                }
            )->where('scheduleId', '<>', 0);
        } else {
            $capital->where(function ($quer) {
                $quer->whereOr('scheduleId = nodeIds')->whereOr(function ($quers) {
                    $quers->where('scheduleId', 'null')->where('state', 7);
                });
            });
        }
        $capital = $capital->group('auxiliary_project_list.capital_id')
            ->select();
        if (count($capital) == 0) {
            //            (new Common())->PushCompletion(3, $orderId);
        }
        foreach ($capital as $k => $item) {
            $username = Db::connect(config('database.db2'))->table('app_user_order_capital')->where('capital_id', $item['capital_id'])->join('app_user', 'app_user.id=app_user_order_capital.user_id', 'left')->where('order_id', $orderId)->whereNull('app_user_order_capital.deleted_at')->column('app_user.username');
            //            if ($type != 1) {
            //                db('auxiliary_project_list')->whereNull('completion_time')->where('capital_id', $item['capital_id'])->update(['completion_time' => time()]);
            //            }
            $capital[$k]['class_b']        .= "         " . implode($username, '/');
            $capital[$k]['Specifications'] = implode(db('capital_value')->where('capital_id', $item['capital_id'])->column('title'), '/');
            $auxiliary_delivery_schedule   = db('auxiliary_delivery_schedule')->join('auxiliary_interactive', 'auxiliary_interactive.id=auxiliary_delivery_schedule.auxiliary_interactive_id', 'left')->field('auxiliary_interactive.title,auxiliary_interactive.main_node,auxiliary_delivery_schedule.id,auxiliary_interactive.upload_acceptance as uploadAcceptance')->where('auxiliary_project_list_id', $item['id'])->select();
            foreach ($auxiliary_delivery_schedule as $p => $value) {
                $app_user_order_nodes = db('auxiliary_delivery_node')->whereIn('auxiliary_delivery_schedul_id', $value['id'])->select();

                if (!empty($app_user_order_nodes)) {
                    $paths = [];
                    foreach ($app_user_order_nodes as $l) {
                        $app_user_order_nodes_list = Db::connect(config('database.db2'))->table('app_user_order_node')
                            ->join('app_user', 'app_user.id=app_user_order_node.user_id', 'left')
                            ->join(config('database')['database'] . '.user', 'user.user_id=app_user_order_node.user_id', 'left')
                            ->field('app_user_order_node.id,app_user_order_node.resource_ids,app_user_order_node.no_watermark_image_ids,app_user_order_node.created_at,if(app_user_order_node.distinguish=1,user.username,app_user.username) as username,app_user_order_node.distinguish')
                            ->whereIn('app_user_order_node.id', $l['node_id'])->select();
                        $pathId                    = implode(array_column($app_user_order_nodes_list, 'resource_ids'), ',');
                        if ($l['type'] == 3) {
                            $pathId                    = implode(array_column($app_user_order_nodes_list, 'no_watermark_image_ids'), ',');
                        }
                        $path                      = Db::connect(config('database.db2'))->table('common_resource')->where('status', 1)->whereIn('id', $pathId)->field('mime_type,path,id')->select();
                        //                        var_dump($path);

                        foreach ($path as $k1 => $o) {

                            $list['path']       = 'https://images.yiniao.co/' . $o['path'];
                            $list['id']         = $o['id'];
                            $list['type']       = $app_user_order_nodes_list[0]['distinguish'];
                            $list['username']   = empty($app_user_order_nodes_list[0]['username']) ? "后台上传" : $app_user_order_nodes_list[0]['username'];
                            $list['created_at'] = date('Y-m-d H:i', $app_user_order_nodes_list[0]['created_at']);
                            $paths[]            = $list;
                        }
                    }
                    $auxiliary_delivery_schedule[$p]['data']    = $paths;
                    $auxiliary_delivery_schedule[$p]['state']   = $app_user_order_nodes[0]['state'];
                    $auxiliary_delivery_schedule[$p]['reason']  = $app_user_order_nodes[0]['reason'];
                    $auxiliary_delivery_schedule[$p]['node_id'] = $app_user_order_nodes[0]['node_id'];
                } else {
                    $auxiliary_delivery_schedule[$p]['state']   = 0;
                    $auxiliary_delivery_schedule[$p]['reason']  = '';
                    $auxiliary_delivery_schedule[$p]['data']    = [];
                    $auxiliary_delivery_schedule[$p]['node_id'] = 0;
                }
            }

            $capital[$k]['data'] = $auxiliary_delivery_schedule;
        }
        return $capital;
    }
    /*
     *
     * 施工节点
     */
    public function Lists($orderId, $type)
    {

        $auxiliaryProjectList = db('auxiliary_delivery_schedule')
            ->where('auxiliary_project_list.order_id', $orderId)
            ->field('
                auxiliary_delivery_schedule.work_process_accept_std_upload_ckp,
                auxiliary_project_list.work_process_title,
                auxiliary_project_list.work_process_important,
                auxiliary_project_list.work_process_sort,
                auxiliary_delivery_schedule.completion_time,
                auxiliary_delivery_schedule.work_process_accept_std_upload_req,
                capital.capital_id,
                capital.categoryName,
                capital.cooperation,
                concat(capital.class_b,"(",square,"/",company,")") as class_b,
                order.state,
                auxiliary_delivery_node.type,
                auxiliary_delivery_node.state as stateNode,
                auxiliary_delivery_node.reason,
                auxiliary_delivery_schedule.id,
                group_concat(auxiliary_delivery_node.node_id) as node_ids,
                group_concat(auxiliary_delivery_node.adn_id) as adn_id,
                auxiliary_project_list.work_process_id
            ')
            ->join('auxiliary_project_list', 'auxiliary_project_list.id=auxiliary_delivery_schedule.auxiliary_project_list_id', 'left')
            ->join('auxiliary_delivery_node', 'auxiliary_delivery_node.auxiliary_delivery_schedul_id=auxiliary_delivery_schedule.id and auxiliary_delivery_node.state !=3', 'left')
            ->join('capital', 'capital.capital_id=auxiliary_project_list.capital_id', 'left')
            ->join('order', 'order.order_id=auxiliary_project_list.order_id', 'left')
            ->where('auxiliary_delivery_schedule.work_process_accept_std_type', 3)
            ->where('auxiliary_project_list.work_process_type', 1)
            ->whereNull('auxiliary_project_list.delete_time')
            ->group('auxiliary_delivery_schedule.id');
        if ($type == 1) {
            $auxiliaryProjectList->whereNull('auxiliary_project_list.completion_time');
        } else {
            $auxiliaryProjectList->whereNotNull('auxiliary_project_list.completion_time');
        }
        $list = $auxiliaryProjectList->where('auxiliary_project_list.work_process_type', 1)->select();


        foreach ($list as $k => $item) {
            $Img = [];
            if ($item['node_ids'] && $item['stateNode'] != 3) {

                $app_user_order_nodes_list = Db::connect(config('database.db2'))->table('app_user_order_node')
                    ->join('app_user', 'app_user.id=app_user_order_node.user_id', 'left')
                    ->join(config('database')['database'] . '.user', 'user.user_id=app_user_order_node.user_id', 'left')
                    ->field('app_user_order_node.id,app_user_order_node.resource_ids,app_user_order_node.no_watermark_image_ids,app_user_order_node.created_at,if(app_user_order_node.distinguish=1,user.username,app_user.username) as username,app_user_order_node.distinguish')
                    ->whereIn('app_user_order_node.id', $item['node_ids'])->select();
                $Img = [];
                foreach ($app_user_order_nodes_list as  $value) {
                    $pathId                    = $value['resource_ids'];
                    $username = $value['username'];
                    if ($item['type'] == 3) {
                        $pathId                    = $value['no_watermark_image_ids'];
                        $username = '后台上传';
                    }
                    $path                      = Db::connect(config('database.db2'))->table('common_resource')->where('status', 1)->whereIn('id', $pathId)->field('mime_type,path,id')->select();

                    foreach ($path as $k1 => $o) {

                        $listArray['path']       = 'https://images.yiniao.co/' . $o['path'];
                        $listArray['id'] =  $item['adn_id'];
                        $listArray['state'] =  $item['stateNode'];
                        $listArray['type']       = $app_user_order_nodes_list[0]['distinguish'];
                        $listArray['username']   = $username;
                        $listArray['created_at'] = date('Y-m-d H:i', $app_user_order_nodes_list[0]['created_at']);
                        $Img[] = $listArray;
                    }
                }
                $list[$k]['Img'] = $Img;
            } else {
                $list[$k]['node_ids'] = []; // 没有节点数据时设为空数组
                $list[$k]['Img'] = null;
            }
        }
        // 初始化结果数组
        $result = [];

        // 双重分组处理
        foreach ($list as $item) {
            $capitalId = $item['capital_id'];
            $work_process_id = $item['work_process_id'];

            // 构建当前项的简化数据（数组形式）

            //是否展示0上传未完成暂时无法验收1验收2验收已完成

            if ($item['work_process_accept_std_upload_req'] == 1 && empty($item['Img'])) {
                $state = 0;
            }
            if ($item['work_process_accept_std_upload_req'] == 1 && !empty($item['Img']) && $item['completion_time'] == 0) {
                $state = 1;
            }
            if ($item['work_process_accept_std_upload_req'] == 1 && !empty($item['Img']) && $item['completion_time'] != 0) {
                $state = 2;
            }
            if ($item['work_process_accept_std_upload_req'] != 1 && $item['completion_time'] == 0) {
                $state = 1;
            }

            if ($item['work_process_accept_std_upload_req'] != 1 && $item['completion_time'] != 0) {
                $state = 2;
            }
            $simplifiedItem = [
                'work_process_accept_std_upload_ckp' => $item['work_process_accept_std_upload_ckp'],
                'id' => $item['id'],
                'reason' => $item['reason'],
                'state' => $item['stateNode'],
                'uploadReq' => $item['work_process_accept_std_upload_req'],
                'img' => $item['Img'] ?? null
            ];
            $app_user_order_capital = Db::connect(config('database.db2'))->table('app_user_order_capital')
                ->join('app_user', 'app_user.id=app_user_order_capital.user_id', 'left')
                ->where('app_user_order_capital.capital_id', $capitalId)->column('app_user.username');
            // 按 capital_id 分组
            if (!isset($result[$capitalId])) {
                $result[$capitalId] = [
                    'capital_id' => $capitalId,
                    'order_id' => $orderId,
                    'class_b' =>  $item['class_b'],
                    'categoryName' =>  $item['categoryName'],
                    'username' => implode("/", $app_user_order_capital),
                    'cooperation' =>  $item['cooperation'],
                    'specifications' => implode(db('capital_value')->where('capital_id', $item['capital_id'])->column('title'), '/'),
                    'state' =>  $item['state'],
                    'date' => []
                ];
            }

            // 检查当前 work_process_title 是否已存在于 date 数组中
            $titleExists = false;
            foreach ($result[$capitalId]['date'] as &$group) {
                if ($group['work_process_id'] === $work_process_id) {
                    // 存在则追加数据到 data 数组
                    $group['data'][] = $simplifiedItem;
                    $titleExists = true;
                    break;
                }
            }

            // 不存在则创建新的 work_process_title 分组
            if (!$titleExists) {
                $result[$capitalId]['date'][] = [
                    'work_process_title' => $item['work_process_title'],
                    'work_process_id' => $item['work_process_id'],
                    'state' => $state,
                    'cooperation' =>  $item['cooperation'],
                    'data' => [$simplifiedItem] // 以数组形式存储数据
                ];
            }
        }

        // 转换为索引数组（保持顺序）
        $finalResult = array_values($result);
        $result   = array();
        $tageList = null;
        foreach ($finalResult as $k => $v) {

            $result[$v['categoryName']][] = $v;
        }
        foreach ($result as $k => $list) {
            $schemeTag['title'] = $k;
            $schemeTag['data']  = $result[$k];
            $tageList[]         = $schemeTag;
        }
        return $tageList;
    }


    /*
     *
     * 施工节点审核
     */
    public function toExamine($nodeIds, $state, $reason, $orderId, $userId)
    {
        db()->startTrans();
        try {

            $time = time();

            $auxiliary_delivery_schedule = db('auxiliary_delivery_schedule')
                ->field('auxiliary_delivery_schedule.id,auxiliary_interactive.title,GROUP_CONCAT(auxiliary_delivery_node.node_id) as node_id,auxiliary_interactive.upload_acceptance,auxiliary_interactive.user_confirm')
                ->join('auxiliary_interactive', 'auxiliary_interactive.id=auxiliary_delivery_schedule.auxiliary_interactive_id', 'left')
                ->join('auxiliary_delivery_node', 'auxiliary_delivery_node.auxiliary_delivery_schedul_id=auxiliary_delivery_schedule.id', 'left')
                ->whereIn('auxiliary_delivery_schedule.id', $nodeIds)
                ->group('auxiliary_delivery_schedule.auxiliary_interactive_id')
                //                ->where('user_confirm', 1)
                ->select();
            $upload_acceptance           = [];
            if (!empty($auxiliary_delivery_schedule)) {
                foreach ($auxiliary_delivery_schedule as $item) {
                    if ($item['user_confirm'] == 1) {
                        $ccPush = new ccPush(1, 'template_node_check', 'exchange_topic', 'template.nodeCheck');
                        if (!empty($item['node_id'])) {
                            $list   = [
                                'orderId' => $orderId,
                                'node' => $item['title'],
                                "time" => date('Y-m-d H:i:s', $time),
                                "nodeId" => $item['node_id']
                            ];
                            $ccPush->push(json_encode($list), 'template_node_check', 'exchange_topic', 'template.nodeCheck');
                            nodeAutoConfirm($item['node_id'], $orderId);
                        }
                    }
                    if ($item['upload_acceptance'] == 2 &&  $item['node_id'] == 0) {
                        $upload_acceptance[] = [
                            'auxiliary_delivery_schedul_id' => $item['id'],
                            'state' => 0,
                            'upload_time' => time(),
                            'mast_id' => $userId,
                            'type' => 2,
                        ];
                    }
                }
            }
            if (!empty($upload_acceptance)) {
                db('auxiliary_delivery_node')->insertAll($upload_acceptance);
            }
            $auxiliary_delivery_node = db('auxiliary_delivery_node')->whereIn('auxiliary_delivery_schedul_id', $nodeIds)->update(['state' => $state, 'reason' => $reason, 'audit_time' => $time]);
            if ($auxiliary_delivery_node) {
                $auxiliary_delivery_schedule = db('auxiliary_delivery_schedule')->join('auxiliary_project_list', 'auxiliary_project_list.id=auxiliary_delivery_schedule.auxiliary_project_list_id', 'left')->whereIn('auxiliary_delivery_schedule.id', $nodeIds)->field('auxiliary_project_list.capital_id,auxiliary_delivery_schedule.auxiliary_interactive_id')->group('auxiliary_interactive_id')->select();
                $payment                     = db('payment')->where('orders_id', $orderId)->where('cleared_time', '>', 0)->select();
                $Lasttime                    = strtotime(date('Y-m-d 21:00:00', $time));
                $more                        = $Lasttime - $time;
                $redis                       = new RedisPackage();
                $clock_in_scan               = $redis::get('template_proccess' . $orderId);
                $sign                        = db('sign')->where('order_id', $orderId)->find();
                if (!empty($sign) && !empty($sign['main_mode_type1'])) {
                    foreach ($auxiliary_delivery_schedule as $li) {
                        if ($li['auxiliary_interactive_id'] == $sign['auxiliary_interactive_id'] && $li['capital_id'] == $sign['main_mode_type1']) {
                            (new Common())->PushCompletion(2, $orderId, strtotime(date("Y-m-d 09:30:00", strtotime("+1 day"))) - time());
                        }
                    }
                }
                if (empty($clock_in_scan) && $clock_in_scan != 1) {
                    $ccPush = new ccPush($more, 'delay_template_proccess', 'delay_topic', 'delay.template_proccess');
                    $list   = [
                        'orderId' => $orderId,
                        'zhifu' => !empty($payment) ? 1 : 0,
                        "time" => date('Y-m-d H:i:s', $time)
                    ];
                    $ccPush->push(json_encode($list), 'delay_template_proccess', 'delay_topic', 'delay.template_proccess');
                    $redis::set('template_proccess' . $orderId, 1);
                }
            }
            db()->commit();
            Db::connect(config('database.db2'))->commit();
            $auxiliary_delivery_node = \db('auxiliary_delivery_node')
                ->field('count(auxiliary_delivery_schedul_id) as nodeId,sum(DISTINCT if(auxiliary_delivery_node.state=1,1,0)) as nodeIds,auxiliary_delivery_schedul_id')
                ->group('auxiliary_delivery_schedul_id')
                ->buildSql();

            $auxiliary_delivery_schedule = \db('auxiliary_delivery_schedule')
                ->field('count(auxiliary_delivery_schedule.id) as scheduleId,node.nodeId,sum(nodeIds) as nodeIds,node.auxiliary_delivery_schedul_id,auxiliary_delivery_schedule.auxiliary_project_list_id')
                ->join([$auxiliary_delivery_node => 'node'], 'node.auxiliary_delivery_schedul_id=auxiliary_delivery_schedule.id', 'left')
                ->whereNull('auxiliary_delivery_schedule.delete_time')
                ->group('auxiliary_project_list_id')
                ->buildSql();


            $capital         = db('auxiliary_project_list')
                ->join([$auxiliary_delivery_schedule => 'schedule'], 'auxiliary_project_list.id=schedule.auxiliary_project_list_id', 'left')
                ->join('capital', 'capital.capital_id=auxiliary_project_list.capital_id', 'left')
                ->join('order', 'order.order_id=auxiliary_project_list.order_id', 'left')
                ->field('auxiliary_project_list.capital_id,schedule.scheduleId,ifnull(schedule.nodeId,0) as nodeId,ifnull(schedule.nodeIds,0) as nodeIds,schedule.auxiliary_delivery_schedul_id,concat(capital.class_b,"(",square,"/",company,")") as class_b,capital.cooperation,auxiliary_project_list.auxiliary_id,auxiliary_project_list.id,order.state')
                ->where('auxiliary_project_list.order_id', $orderId)
                ->where('capital.types', 1)
                ->where('capital.enable', 1)
                ->whereNull('auxiliary_project_list.delete_time')
                ->where(function ($quer) {
                    $quer->whereOr('scheduleId = nodeIds')->whereOr(function ($quers) {
                        $quers->where('scheduleId', 'null')->where('state', 7);
                    });
                });
            $capital         = $capital->group('auxiliary_project_list.capital_id')
                ->column('auxiliary_project_list.capital_id');
            $completion_time = time();
            db('auxiliary_project_list')->whereNull('completion_time')->whereIn('capital_id', $capital)->update(['completion_time' => $completion_time]);

            $order_setting = db('order_setting')->join('order', 'order_setting.order_id=order.order_id', 'left')->field('order_setting.*,order.*')->where('order.order_id', $orderId)->find();
            if ($order_setting['fast_salary'] == 2) {
                $appcapital_labor_costs = [];
                $app_user_order_capital = db('app_user_order_capital')
                    ->field('app_user_order_capital.personal_price,app_user_order.salary_ratio,app_user_order_capital.id,app_user_order_capital.capital_id,app_user_order_capital.user_id,app_user_order.status,app_user_order.order_id')
                    ->join('app_user_order', 'app_user_order.order_id=app_user_order_capital.order_id and app_user_order.user_id=app_user_order_capital.user_id', 'left')
                    ->join('app_user', 'app_user.id=app_user_order_capital.user_id', 'left')
                    ->where('app_user.origin', 1)
                    ->where('app_user.shortcut', 1)
                    ->whereNull('app_user_order_capital.deleted_at')
                    ->whereIn('app_user_order_capital.capital_id', $capital)
                    ->select();

                $appUser                = db('app_user_order')
                    ->join('app_user_order_capital', 'app_user_order.order_id=app_user_order_capital.order_id and app_user_order.user_id=app_user_order_capital.user_id', 'left')
                    ->join('app_user', 'app_user.id=app_user_order_capital.user_id', 'left')
                    ->join('app_work_type', 'app_work_type.id=app_user.work_type_id', 'left')
                    ->whereNull('app_user_order_capital.deleted_at')
                    ->orderRaw("field(work_type_id,4,5,2,3,1)")
                    ->where('app_user_order.order_id', $orderId)
                    ->where('app_user_order.status', '<', 3)
                    ->where('app_user.origin', 1)
                    ->where('app_user.shortcut', 1)
                    ->group('app_user_order.user_id')
                    ->column('app_user_order.user_id');
                journal(['capital_id' => $capital, 'list' => $app_user_order_capital], 4);
                foreach ($app_user_order_capital as $k => $item) {
                    $app_user_order_capital[$k]['state'] = 0;
                    $listArray                           = $appUser;
                    if ($item['status'] < 3 && count($appUser) > 1) {
                        $app_user_order_capital[$k]['state'] = "-1";
                        foreach ($listArray as $Key => $list) {
                            if ($list == $item['user_id']) {
                                unset($listArray[$Key]);
                            }
                        }
                        $listArray                                 = array_merge($listArray);
                        $app_user_order_capital[$k]['examineName'] = $listArray[0];
                    } else {
                        $app_user_order_capital[$k]['examineName'] = 0;
                    }
                }
                foreach ($app_user_order_capital as $item) {
                    $withdrawal_amount                  = round($item['personal_price'] * ($item['salary_ratio'] / 100), 2);
                    $app_user_order_capital_labor_costs = db('app_user_order_capital_labor_costs')->where(['order_id' => $orderId, 'capital_id' => $item['capital_id'], 'user_id' => $item['user_id']])->lock(true)->find();
                    $examine                            = db('app_user_order_capital_labor_costs')->where(['order_id' => $orderId, 'user_id' => $item['user_id'], 'examine_user_id' => ['<>', 0], 'adopt_time' => ['<>', 0]])->order('id ASC')->find();
                    if (empty($app_user_order_capital_labor_costs)) {
                        $adopt_time = 0;
                        if ($item['examineName'] == 0) {
                            $adopt_time = $completion_time;
                        }
                        if ($item['state'] == "-1" && !empty($examine)) {
                            $item['state']       = "0";
                            $adopt_time          = $examine['adopt_time'];
                            $item['examineName'] = $examine['examine_user_id'];
                        }
                        db('app_user_order_capital_labor_costs')->insert(['order_id' => $orderId, 'capital_id' => $item['capital_id'], 'user_id' => $item['user_id'], 'personal_price' => $withdrawal_amount, 'created_at' => $completion_time, 'state' => $item['state'], 'examine_user_id' => $item['examineName'], 'adopt_time' => $adopt_time]);
                        $appcapital_labor_costs[] = [
                            'capital_id' => $item['capital_id'],
                            'withdrawal_amount' => $withdrawal_amount
                        ];
                    }
                }

                if (!empty($appcapital_labor_costs)) {
                    $result   = array();
                    $tageList = [];

                    foreach ($appcapital_labor_costs as $k => $v) {
                        $result[$v['capital_id']][] = $v;
                    }
                    foreach ($result as $k => $list) {
                        $schemeTag['capital_id'] = $k;
                        $schemeTag['sum']        = array_sum(array_column($list, 'withdrawal_amount'));
                        $tageList[]              = $schemeTag;
                    }
                    if (!empty($tageList)) {
                        foreach ($tageList as $value) {
                            $u8c_voucher = Db::connect(config('database.zong'))->table('u8c_voucher')->lock(true)->where(['orderId' => $orderId, 'relation_id' => $value['capital_id'], 'type' => 53])->find();
                            if (empty($u8c_voucher) && $value['sum'] != 0) {
                                Db::connect(config('database.zong'))->table('u8c_voucher')->insert([
                                    'explanation' => '收到工资快结工序验收师傅金额',
                                    'money' => $value['sum'],
                                    'orderId' => $orderId,
                                    'relation_id' => $value['capital_id'],
                                    'type' => 53,
                                    'create_time' => time() * 1000,
                                    'prepareddate' => date('Y-m-d', time()),
                                ], true);
                            }
                        }
                    }
                }
            }
            return ['code' => 200, 'msg' => ""];
        } catch (\Exception $e) {
            db()->rollBack();
            return ['code' => 300, 'msg' => $e->getMessage()];
        }
    }
    /**
     * 辅助交付节点审核（含快结工资逻辑）- TP5.0适配版
     * @param mixed $nodeIds 节点ID（数组/字符串）
     * @param int $state 审核状态（1通过/2驳回）
     * @param string $reason 审核原因
     * @param int $orderId 订单ID
     * @param int $userId 操作用户ID
     * @param int $capitalId 资金ID
     * @return array
     */
    public function toNewExamine($nodeIds, $state, $reason, $orderId, $userId, $capitalId)
    {
        // TP5.0 事务启动（兼容框架原生方法）
        Db::startTrans();
        try {
            $time = time();
            // 1. 基础参数处理：统一格式+防呆校验（兼容TP5.0数组处理）
            $nodeIdsArr = is_array($nodeIds) ? array_filter($nodeIds) : explode(',', trim($nodeIds));
            $nodeIdsArr = array_unique(array_map('intval', $nodeIdsArr));
            if (empty($nodeIdsArr)) {
                throw new \Exception("节点ID不能为空");
            }
            $reject_status=0;
            $reject_time=0;
            $reject_reason='';
            if($state==2){
                 $reject_status=1;
                 $reject_time=$time;
                 $reject_reason=$reason;
            }

            // 2. 批量更新核心表：TP5.0 whereIn 兼容+索引优化
            $uploadAcceptance = [
                'state' => $state,
                'reason' => $reason ?: '',
                'reject_status'=>$reject_status,
                'reject_time'=>$reject_time,
                'reject_reason'=>$reject_reason,
                'audit_time' => $time
            ];
            // 7. 快结工资逻辑（TP5.0 别名查询+锁机制兼容）
            $orderSetting = Db::name('order_setting')
                ->alias('os')
                ->join('order o', 'os.order_id = o.order_id', 'left')
                ->join('order_info in', 'os.order_id = in.order_id', 'left')
                ->field('os.*, o.*,in.assignor as username')
                ->where('o.order_id', $orderId)
                ->find() ?: [];
            Db::name('auxiliary_delivery_node')
                ->whereIn('auxiliary_delivery_schedul_id', $nodeIdsArr)
                ->update($uploadAcceptance);

            // 审核通过时更新完成时间
            if ($state == 1) {
                Db::name('auxiliary_delivery_schedule')
                    ->whereIn('id', $nodeIdsArr)
                    ->update(['completion_time' => $time]);
            }

            // 3. 合并查询：TP5.0 闭包查询兼容+减少重复查库
            $deliveryScheduleData = Db::name('auxiliary_delivery_schedule')
            ->where('capital_id', $capitalId)
            ->where('order_id', $orderId)
            ->whereNull('delete_time')
            ->where('work_process_accept_std_type', 3)
            ->select();
         // 4. 辅助项目列表查询（TP5.0 find 兼容）
            $auxiliaryProjectList = Db::name('auxiliary_project_list')
                ->where('capital_id', $capitalId)
                ->where('order_id', $orderId)
                ->find() ?: [];

            // 整体完成判断（优化空数组处理）
            $complete = 0;
            $completionTimes=array_column($deliveryScheduleData,'completion_time');
            if ((!empty($completionTimes) && !in_array(0, $completionTimes)) || !empty($auxiliaryProjectList['completion_time'])) {
                $complete = 1;
                if (empty($auxiliaryProjectList['completion_time'])) {
                    Db::name('auxiliary_project_list')
                        ->where('capital_id', $capitalId)
                        ->where('order_id', $orderId)
                        ->update(['completion_time' => $time]);
                }

                // 生成流程编码（TP5.0 json_encode 兼容）
                $auxiliaryProjectListIds = Db::name('auxiliary_project_list')
                    ->where('capital_id', $capitalId)
                    ->where('order_id', $orderId)
                    ->column('id');
                $processCode = json_encode([
                    'processCode' => array_map('strval', $auxiliaryProjectListIds)
                ], JSON_UNESCAPED_SLASHES);
                openapiAddTask($orderId, 12, '店长工序验收完成', $processCode);
            }
            // 6. 审核驳回逻辑（TP5.0 多表查询兼容）
            $auxiliaryDeliveryNode = Db::name('auxiliary_delivery_node')
                ->whereIn('auxiliary_delivery_schedul_id', $nodeIdsArr)
                ->where('type', 1)
                ->select();
            if (!empty($auxiliaryDeliveryNode)) {
                if ($state == 2) {
                    // 批量查询关联数据（避免循环内查库）
                    $mastIds = array_column($auxiliaryDeliveryNode, 'mast_id');
                    $orderTimes = Db::name('order_times')->where('order_id', $orderId)->find() ?: [];
                    // TP5.0 keyBy 兼容（手动构建索引，避免框架版本差异）
                    $appUsers = Db::name('app_user')->whereIn('id', $mastIds)->select();
                    $appUsersMap = [];
                    foreach ($appUsers as $user) {
                        $appUsersMap[$user['id']] = $user;
                    }

                    // 跨库查询（TP5.0 连接指定数据库）
                    $scanEvaluationScores = Db::connect(config('database.zong'))
                        ->name('scan_evaluation_score')
                        ->where([
                            'order_id' => $orderId,
                            'user_type' => 2,
                            'types' => 3
                        ])
                        ->whereIn('user_id', $mastIds)
                        ->select();
                    $scoreMap = [];
                    foreach ($scanEvaluationScores as $score) {
                        $scoreMap[$score['user_id']] = $score;
                    }

                    // 收集质检数据（批量插入优化）
                    foreach ($auxiliaryDeliveryNode as $item) {
                        $mobile = $appUsersMap[$item['mast_id']]['mobile'] ?? 0;
                        // 无评分记录则插入
                        if (!isset($scoreMap[$item['mast_id']])) {
                            Db::connect(config('database.zong'))
                                ->name('scan_evaluation_score')
                                ->insert([
                                    'order_id' => $orderId,
                                    'user_id' => $item['mast_id'],
                                    'user_type' => 2,
                                    'types' => 3,
                                    'user_phone' => $mobile,
                                    'relation_id' => $capitalId,
                                    'score' => '-2',
                                    'city_id' => config('cityId'),
                                    'create_time' => $time,
                                    'score_time' => $time,
                                    'store_id' => $orderSetting['store_id'] ?? 0,
                                    'channel_id' => $orderSetting['channel_id'] ?? 0,
                                    'channel_details' => $orderSetting['channel_details'] ?? '',
                                    'pro_id' => $orderSetting['pro_id'] ?? 0,
                                    'pro_id1' => $orderSetting['pro_id1'] ?? 0,
                                    'pro_id2' => $orderSetting['pro_id2'] ?? 0,
                                    'con_time' => $orderTimes['signing_time'] ?? 0,
                                    'change_work_time' => $orderTimes['change_work_time'] ?? 0,
                                    'business_id' => $orderSetting['business_id'] ?? 0,
                                    'content' => $orderSetting['order_no'] ?? ''
                                ]);
                        }
                    }
                }
                $inspectionDataList = [];
                foreach ($auxiliaryDeliveryNode as $items) {
                    foreach ($deliveryScheduleData as $values) {
                        if ($values['id'] == $items['auxiliary_delivery_schedul_id']) {
                            $inspectionDataList[] = [
                                'order_id' => $orderId,
                                'node_type' => 1,
                                'node_id' => $items['node_id'] ?? 0,
                                'work_process_id' => $values['work_process_id'] ?? 0,
                                'capital_id' => $capitalId,
                                'auxiliary_interactive_id' => 0,
                                'user_id' => $userId ?? 0,
                                'master_type' => 2,
                                'master_id' => $items['mast_id'] ?? 0,
                                'admin_type' => 1,
                                'admin_id' => $orderSetting['assignor'] ?? 0,
                                'admin_name' => $orderSetting['username'] ?? '',
                                'approval_status' => $state,
                                'voucher' => '',
                                'content' => $reason ?: '',
                                'create_time' => $time
                            ];
                        }
                    }
                }
                if (!empty($inspectionDataList)) {
                    Db::name('auxiliary_inspection')->insertAll($inspectionDataList);
                }
            }
 


            if ($orderSetting['fast_salary'] == 2 && $complete == 1) {
                // 关联查询（TP5.0 别名+多表连接兼容）
                $appUserOrderCapital = Db::name('app_user_order_capital')
                    ->alias('auoc')
                    ->join('app_user_order auo', 'auo.order_id = auoc.order_id AND auo.user_id = auoc.user_id', 'left')
                    ->join('app_user au', 'au.id = auoc.user_id', 'left')
                    ->field('auoc.personal_price, auo.salary_ratio, auoc.id, auoc.capital_id, auoc.user_id, auo.status, auo.order_id')
                    ->where('au.origin', 1)
                    ->where('au.shortcut', 1)
                    ->whereNull('auoc.deleted_at')
                    ->where('auoc.capital_id', $capitalId)
                    ->select();
                if (empty($appUserOrderCapital)) {
                    Db::commit();
                    return ['code' => 200, 'msg' => ""];
                }

                // 排序查询（TP5.0 orderRaw 兼容）
                $appUserIds = Db::name('app_user_order')
                    ->alias('auo')
                    ->join('app_user_order_capital auoc', 'auo.order_id = auoc.order_id AND auo.user_id = auoc.user_id', 'left')
                    ->join('app_user au', 'au.id = auoc.user_id', 'left')
                    ->join('app_work_type awt', 'awt.id = au.work_type_id', 'left')
                    ->whereNull('auoc.deleted_at')
                    ->where('auo.order_id', $orderId)
                    ->where('auo.status', '<', 3)
                    ->where('au.origin', 1)
                    ->where('au.shortcut', 1)
                    ->group('auo.user_id')
                    ->orderRaw("field(awt.id,4,5,2,3,1)")
                    ->column('auo.user_id');

                // 处理用户状态（引用传递兼容）
                foreach ($appUserOrderCapital as &$item) {
                    $item['state'] = 0;
                    $item['examineName'] = 0;
                    if ($item['status'] < 3 && count($appUserIds) > 1) {
                        $item['state'] = "-1";
                        $userIndex = array_search($item['user_id'], $appUserIds);
                        if ($userIndex !== false && $userIndex < count($appUserIds) - 1) {
                            $item['examineName'] = $appUserIds[$userIndex + 1];
                        }
                    }

                    // 历史审核记录查询（TP5.0 where 多条件兼容）
                    $examine = Db::name('app_user_order_capital_labor_costs')
                        ->where('order_id', $orderId)
                        ->where('user_id', $item['user_id'])
                        ->where('examine_user_id', '<>', 0)
                        ->where('adopt_time', '<>', 0)
                        ->order('id ASC')
                        ->find();
                    if ($item['state'] == "-1" && !empty($examine)) {
                        $item['state'] = "0";
                        $item['adopt_time'] = $examine['adopt_time'];
                        $item['examineName'] = $examine['examine_user_id'];
                    }
                }
                unset($item);

                // 工资成本记录（TP5.0 行锁兼容，用lock(true)）
                $capitalLaborCosts = [];
                foreach ($appUserOrderCapital as $item) {
                    $withdrawalAmount = round($item['personal_price'] * ($item['salary_ratio'] / 100), 2);
                    $laborCost = Db::name('app_user_order_capital_labor_costs')
                        ->where([
                            'order_id' => $orderId,
                            'capital_id' => $item['capital_id'],
                            'user_id' => $item['user_id']
                        ])
                        ->lock(true)
                        ->find();

                    if (empty($laborCost)) {
                        $adoptTime = $item['examineName'] == 0 ? $time : ($item['adopt_time'] ?? 0);
                        Db::name('app_user_order_capital_labor_costs')->insert([
                            'order_id' => $orderId,
                            'capital_id' => $item['capital_id'],
                            'user_id' => $item['user_id'],
                            'personal_price' => $withdrawalAmount,
                            'created_at' => $time,
                            'state' => $item['state'],
                            'examine_user_id' => $item['examineName'],
                            'adopt_time' => $adoptTime
                        ]);

                        $capitalLaborCosts[] = [
                            'capital_id' => $item['capital_id'],
                            'withdrawal_amount' => $withdrawalAmount
                        ];
                    }
                }

                // 批量插入U8C凭证（跨库+行锁兼容）
                if (!empty($capitalLaborCosts)) {
                    $capitalSumMap = [];
                    foreach ($capitalLaborCosts as $cost) {
                        $capId = $cost['capital_id'];
                        $capitalSumMap[$capId] = ($capitalSumMap[$capId] ?? 0) + $cost['withdrawal_amount'];
                    }

                    foreach ($capitalSumMap as $capId => $sumAmount) {
                        if ($sumAmount <= 0) continue;
                        $u8cVoucher = Db::connect(config('database.zong'))
                            ->name('u8c_voucher')
                            ->lock(true)
                            ->where([
                                'orderId' => $orderId,
                                'relation_id' => $capId,
                                'type' => 53
                            ])
                            ->find();

                        if (empty($u8cVoucher)) {
                            Db::connect(config('database.zong'))
                                ->name('u8c_voucher')
                                ->insert([
                                    'explanation' => '收到工资快结工序验收师傅金额',
                                    'money' => $sumAmount,
                                    'orderId' => $orderId,
                                    'relation_id' => $capId,
                                    'type' => 53,
                                    'create_time' => $time * 1000,
                                    'prepareddate' => date('Y-m-d', $time),
                                ]);
                        }
                    }
                }

                // 日志记录（保持原有逻辑）
                journal(['capital_id' => $capitalId, 'list' => $appUserOrderCapital], 4);
            }

            Db::commit();
            return ['code' => 200, 'msg' => ""];
        } catch (\Exception $e) {
            Db::rollback();
            // TP5.0 日志记录兼容（建议启用框架日志）
            return ['code' => 300, 'msg' => $e->getMessage()];
        }
    }


    public function initial($order_id)
    {
        $auxiliary_interactive = db('auxiliary_delivery_schedule')->where('auxiliary_delivery_schedule.order_id', $order_id)->where('capital_id', 241000000431688)->whereNull('delete_time')->where('auxiliary_delivery_schedule.work_process_accept_std_type', 3)->select();

        foreach ($auxiliary_interactive as $item) {
            $auxiliary_interactiveCount = db('auxiliary_delivery_node')->where('auxiliary_delivery_node.state', 1)->where('auxiliary_delivery_schedul_id', $item['id'])->select();
            if (!empty($auxiliary_interactiveCount) || $item['work_process_accept_std_upload_req'] != 1) {
                db('auxiliary_delivery_schedule')->where('id', $item['id'])->update(['completion_time' => time()]);
            }
        }
    }
    public function oldAdd($data, $params, $common, $resource, $user_id)
    {
        Db::connect(config('database.db2'))->startTrans();
        db()->startTrans();
        try {

            $startup  = db('startup')->join('order', 'order.order_id=startup.orders_id', 'left')->where('orders_id', $params['order_id'])->find();
            //派单师傅
            $relation     = \db('app_user')
                ->field('app_user.username,app_user.origin')
                ->whereIn('id', $startup['xiu_id'])
                ->select();
            $cooperation  = [];
            $cooperation1 = [];
            foreach ($relation as $item) {
                if ($item['origin'] == 2) {
                    $cooperation[] = $item;
                } else {
                    $cooperation1[] = $item;
                }
            }
            if (!empty($cooperation) && empty($cooperation1) && empty($startup['start_time'])) {
                db('order')->where('order_id', $params['order_id'])->whereNull('start_time')->update(['start_time' => time()]);
            }
            if (!empty($resource)) {
                $listNode = $this->addResourceIds($resource);
                $params['no_watermark_image_ids'] = implode(',', $listNode['no_watermark_image']);
                $params['resource_ids'] = implode(',', $listNode['resource_ids']);
            }
            $params['describe']    = '';
            $params['user_id']     = $user_id;
            $params['type']        = 2;
            $params['status']      = 1;
            $params['distinguish'] = 1;
            $params['created_at']  = time();
            $params['updated_at']  = time();
            $orderNode             = Db::connect(config('database.db2'))->table('app_user_order_node')->insertGetId($params);
            \db('auxiliary_delivery_node')->insert(['auxiliary_delivery_schedul_id' => $data['nodeChildId'], 'state' => 0, 'node_id' => $orderNode, 'mast_id' => $user_id, 'type' => 2, 'upload_time' => time()]);
            $common->MultimediaResources($params['order_id'], $user_id, $resource, 9);
            db()->commit();
            Db::connect(config('database.db2'))->commit();

            return ['code' => 200];
        } catch (\Exception $e) {
            Db::connect(config('database.db2'))->rollBack();
            db()->rollBack();
            return ['code' => 300, 'message' => $e->getMessage()];
        }
    }
    public function newAdd($params, $common, $resource, $user_id)
    {
        Db::connect(config('database.db2'))->startTrans();
        db()->startTrans();
        try {
            $startup  = db('startup')->join('order', 'order.order_id=startup.orders_id', 'left')->where('orders_id', $params['orderId'])->find();
            //派单师傅
            $relation     = \db('app_user')
                ->field('app_user.username,app_user.origin')
                ->whereIn('id', $startup['xiu_id'])
                ->select();
            $cooperation  = [];
            $cooperation1 = [];
            foreach ($relation as $item) {
                if ($item['origin'] == 2) {
                    $cooperation[] = $item;
                } else {
                    $cooperation1[] = $item;
                }
            }
            if (!empty($cooperation) && empty($cooperation1) && empty($startup['start_time'])) {
                db('order')->where('order_id', $params['orderId'])->whereNull('start_time')->update(['start_time' => time()]);
            }
            if (!empty($resource)) {
                $ImgList = [];
                $ImgArray = [];

                foreach ($resource as  $k => $item) {
                    $list = [];
                    $oldList = [];
                    if (isset($item['listImg'])) {
                        foreach ($item['listImg'] as $value) {
                            $path      = parse_url($value['path'])['path'];
                            array_push($ImgArray, $value['path']);
                            $listItem = [
                                'mime_type' => 1,
                                'path' => $path,
                                'size' => 0,
                                'created_at' => time(),
                                'no_watermark_image_ids' => $value['no_watermark_image_ids'] ?? '',
                                'id' => $value['id']
                            ];
                            $list[] = $listItem;
                            if (isset($value['fileEntity'])) {
                                $oldList[] = $listItem;
                            }
                        }
                        $ImgList[$k]['img'] = $list;
                        $ImgList[$k]['oldImg'] = $oldList;
                        $ImgList[$k]['id'] = $item['id'];

                        db('auxiliary_delivery_node')->where('auxiliary_delivery_schedul_id', $item['id'])->delete();
                    }
                    if (empty($item['listImg'])) {
                        db('auxiliary_delivery_node')->where('auxiliary_delivery_schedul_id', $item['id'])->delete();
                    }
                }
            }
            foreach ($ImgList as $value) {
                $resource_ids = [];
                $no_watermark_image_ids = [];
                foreach ($value['img'] as $item) {
                    $info           = Db::connect(config('database.db2'))->table('common_resource')->where('path', $item['path'])->find();
                    if (empty($info)) {
                        $id = Db::connect(config('database.db2'))->table('common_resource')->insertGetId(['mime_type' => $item['mime_type'], 'path' => $item['path'], 'size' => $item['size'] ?? 0, 'created_at' => time()]);
                    } else {
                        $id = $info['id'];
                    }
                    if (isset($item['no_watermark_image_ids']) && $item['no_watermark_image_ids'] != '') {
                        $no_watermark_image_ids[] = $item['no_watermark_image_ids'];
                    }
                    $resource_ids[] = $id;
                }
                $resource_old_ids = [];
                if (empty($value['oldImg'])) {
                    foreach ($value['oldImg'] as $item) {
                        $info           = Db::connect(config('database.db2'))->table('common_resource')->where('path', $item['path'])->find();

                        if (empty($info)) {
                            $id = Db::connect(config('database.db2'))->table('common_resource')->insertGetId(['mime_type' => $item['mime_type'], 'path' => $item['path'], 'size' => $item['size'] ?? 0, 'created_at' => time()]);
                        } else {
                            $id = $info['id'];
                        }

                        $resource_old_ids[] = $id;
                    }
                }
                if (!empty($no_watermark_image_ids)) {
                    $no_watermark_image_ids = array_unique($no_watermark_image_ids);
                    $resource_old_ids = array_merge($resource_old_ids, $no_watermark_image_ids);
                }
                $params['no_watermark_image_ids'] = implode(',', $resource_old_ids);
                $param['resource_ids'] = implode(',', $resource_ids);
                $param['describe']    = '';
                $param['order_id']    = $params['orderId'];
                $param['user_id']     = $user_id;
                $param['type']        = 2;
                $param['lng']        = $params['lng'];
                $param['lat']        = $params['lat'];
                $param['status']      = 1;
                $param['distinguish'] = 1;
                $param['created_at']  = time();
                $param['updated_at']  = time();

                $state = 3;
                if ($params['type'] == 1) {
                    $state = 0;
                }
                $orderNode             = Db::connect(config('database.db2'))->table('app_user_order_node')->insertGetId($param);

                \db('auxiliary_delivery_node')->insert(['auxiliary_delivery_schedul_id' => $value['id'], 'state' => $state, 'node_id' => $orderNode, 'mast_id' => $user_id, 'type' => 2, 'upload_time' => time()]);
            }

            if (!empty($ImgArray)) {
                $common->MultimediaResources($params['orderId'], $user_id, $ImgArray, 9);
            }



            db()->commit();
            Db::connect(config('database.db2'))->commit();
            return ['code' => 200];
        } catch (\Exception $e) {
            Db::connect(config('database.db2'))->rollBack();
            db()->rollBack();
            return ['code' => 300, 'message' => $e->getMessage()];
        }
    }

    /**
     * 添加资源返回ID
     * @param $resources
     * @return array
     */
    public function addResourceIds($resources)
    {

        $resource_ids = [];
        $resource_old_ids = [];
        $aLi = new  Aliyunoss();
        foreach ($resources as $item) {
            if (!isset($item['mime_type']) || !isset($item['file_path'])) {
                r_date(null, 300, '资源格式错误');
            }
            $info           = Db::connect(config('database.db2'))->table('common_resource')->where('path', $item['file_path'])->find();
            $resource_ids[] = Db::connect(config('database.db2'))->table('common_resource')->insertGetId(['mime_type' => $item['mime_type'], 'path' => $item['file_path'], 'size' => $item['size'] ?? 0, 'created_at' => time()]);

            if (isset($item['oldImg']) && $item['oldImg'] != '') {
                $path = $item['file_path'];
                $filename = pathinfo($path)['dirname'] . '/' . pathinfo($path)['filename'] . '_OLD.' . pathinfo($path)['extension'];
                $parts = parse_url($item['oldImg']);
                $l = $aLi->copyObject(ltrim($parts['path'], '/'), $filename);
                if ($l['info']['http_code'] != 200) {
                    r_date(null, 300, '图片上传错误');
                }
                $resource_old_ids[] = Db::connect(config('database.db2'))->table('common_resource')->insertGetId(['mime_type' => $item['mime_type'], 'path' => $filename, 'size' => $item['size'] ?? 0, 'created_at' => time()]);
            } else {
                $resource_old_ids[] = Db::connect(config('database.db2'))->table('common_resource')->insertGetId(['mime_type' => $item['mime_type'], 'path' => $item['file_path'], 'size' => $item['size'] ?? 0, 'created_at' => time()]);
            }
        }
        return ['resource_ids' => $resource_ids, 'no_watermark_image' => $resource_old_ids];
    }
}
